/**
 *	usage:
 *		var GET = require('./php-get.js')
 *		...
 *		var myget = GET.parse(request.url)
 *		if (myget.location == 'london') { ... }
**/

"use strict"

//break the url into components using the PHP idiom
exports.parse = function(url) {
	var	GET = {}
	
	var a = url.indexOf('?')
	if (a > -1) {
		var tmpval, tmp = url.substr(a+1).split('&')		//create each key / val pair
			
		for (var i=0; i<tmp.length; i++) {
			tmpval = tmp[i].split('=')						//split into pairs
			GET[tmpval[0]] = tmpval[1]						//assign as GET.key = val
		}
	}
	
	//GET.toString = createToString(GET)						//helpfully create a toString method
	return GET												//return our result
}

var createToString = function(obj) {
	var objstr = JSON.stringify(obj)
	return function() {
		return objstr
	}
}